//
//  ModuleOneViewController.m
//  iOSDemo
//
//  Created by login on 15-6-29.
//  Copyright (c) 2015年 login. All rights reserved.
//

#import "ModuleViewController.h"
#import "BeginCityViewController.h"
#import "DestinationViewController.h"
#import "Header.h"
#import "NextViewController.h"
@interface ModuleViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_moduleOneTableView;
    NSArray *_moduleOneList;
    NSMutableDictionary *viewDic;
}

@end

@implementation ModuleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    viewDic = [NSMutableDictionary dictionary];
    viewDic = [self.dict copy];
    
    _moduleOneList = [viewDic allKeys];
    [self initUITableView];
    [self setNavigateBar];
}
-(void) setNavigateBar{
    
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:21],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    backButton.titleLabel.font = [UIFont systemFontOfSize:16];
    backButton.titleLabel.textColor = [UIColor whiteColor];
    [backButton addTarget:self action:@selector(backController) forControlEvents:UIControlEventTouchUpInside];
    backButton.size = CGSizeMake(80, 30);
    
    backButton.titleEdgeInsets = UIEdgeInsetsMake(0, 3, 0, 0);
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    negativeSpacer.width = -15;
    self.navigationItem.leftBarButtonItems = @[negativeSpacer,[[UIBarButtonItem alloc]initWithCustomView:backButton]];
}
-(void) backController{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
   
}
- (void)initUITableView
{
    _moduleOneTableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _moduleOneTableView.delegate = self;
    _moduleOneTableView.dataSource = self;
    [self.view addSubview:_moduleOneTableView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _moduleOneList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    cell.textLabel.text = _moduleOneList[indexPath.row];
    
    return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//反射机制
    NSString *string = _moduleOneList[(int)indexPath.row];
    NextViewController *vi = [[NextViewController alloc]init];
    UIViewController *view = [vi turnToNextViewController:string andDic:viewDic];
    [self.navigationController pushViewController:view animated:YES];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
